package com.lxq.LeetCode.twoSum;

import java.util.*;

public class Main01 {
    public static long[] twoSum(int[] nums,int target){
        Map<Integer, Integer> hashtable = new HashMap<>();
        for (int i=0;i<nums.length;i++){
            if (hashtable.containsKey(target-nums[i])){
                return new long[]{hashtable.get(target-nums[i]),i};
            }
            hashtable.put(nums[i],i);
        }
        return  new long[0];
    }
//    public static long[] twoSum(int[] nums, int target){
//        HashMap<Long, Integer> hm = new HashMap<Long, Integer>();
//        long[] aws = new long[2];
//        for (int i=0;i<nums.length;i++){
//            hm.put((long)nums[i],i);
//        }
//        for (int i=0;i<nums.length;i++){
//            if (nums[i]<target && hm.containsKey((long)target-nums[i])){
//
//                aws[0]=i;
//                aws[1]=hm.get((long)target-nums[i]);
//                if (aws[0]!=aws[1]){
//                    return aws;
//                }
//
//            }
//        }
//        return aws;
//    }
    public static void main(String[] args) {
        int[] num = {0,1,2,0};
        int target = 0;
        long[] aws = twoSum(num,target);
        System.out.println(aws[0]+","+aws[1]);
    }
}
